package com.tian.user.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.tian.authen.api.feign.response.OauthAccessTokenResponse;
import com.tian.authen.service.IUserService;
import com.tian.user.dao.UserDao;
import com.tian.user.entity.User;
import com.tian.user.feign.AuthenFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.tian.user.entity.table.UserTableDef.USER;

/**
 * @author zhumengping
 * @title: UserServiceImpl
 * @projectName zhump-cloud
 * @date 2023/8/10 9:45
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements IUserService {


    @Autowired
    private AuthenFeignClient feignClient;

    @Autowired
    private UserDao userDao;


    @Override
    public User getUserByUser(String token) {
        OauthAccessTokenResponse bean = feignClient.getToken(token);
        QueryWrapper where = new QueryWrapper().create()
                .select(USER.ALL_COLUMNS)
                .from(USER)
                .where(USER.USER_NAME.eq(bean.getUserName()));
        return userDao.selectOneByQuery(where);
    }
}
